/*   
 * Copyright (c) 2016-2020 canaanQd. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * canaanQd. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with canaanQd.   
 *   
 */ 

package com.lg.wechat.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.lg.config.BootLgConfig;
import com.lg.wechat.common.handler.WxAuthenInterceptor;

@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter  {
	
	@Autowired
	BootLgConfig bootLgConfig;
	
	@Bean
	WxAuthenInterceptor wxAuthenInterceptor() {
         return new WxAuthenInterceptor();
    }
	
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
		List<String> paths=new ArrayList<>();
		paths.add("/css/**");
		paths.add("/js/**");
		paths.add("/fonts/**");
		paths.add("/font/**");
		paths.add("/images/**");
		paths.add("/docs/**");
		paths.add(bootLgConfig.getPathPatterns());
        registry.addInterceptor(wxAuthenInterceptor()).addPathPatterns("/wx/**").excludePathPatterns(paths);//添加wx全局拦截器
    }
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {//添加资源全局拦截器
		registry.addResourceHandler(bootLgConfig.getPathPatterns()).addResourceLocations("file:///"+bootLgConfig.getUploadPath());
	}
}
